package com.example.cloud.stream.rabbitmq.provider.service.impl;

import com.example.cloud.stream.rabbitmq.provider.service.IMessageProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * 消息生产者
 * 当前这个类是source,负责生产消息，并且发送给channel
 *
 * @author Frank
 * @create 2020-12-06 20:20
 **/
@Slf4j
@EnableBinding(Source.class)
public class MessageProviderImpl implements IMessageProvider {

    /**
     * 消息发送管道
     */
    @Resource
    private MessageChannel output;

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        log.info("****serial: "+serial);
        return serial;
    }
}
